package severlet;

import dao.StudentDao;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.Writer;

@WebServlet(name = "ReturnPasswordServlet", value = "/ReturnPasswordServlet")
public class ReturnPasswordServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
doPost(request, response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        response.setCharacterEncoding("utf-8");
        response.setContentType("text/html;charset=utf-8");

        String username = request.getParameter("username");
        String studentname = request.getParameter("studentname");

        StudentDao studentDao=new StudentDao();
        String password = studentDao.returnPassword(username, studentname);

        PrintWriter out= response.getWriter();
        out.println("您的密码为"+password);
        out.println("<a href=\"student_login.jsp\">进入登录页面</a>");
    }
}
